import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class RefreshHeader extends CustomHeader {
  RefreshHeader({Key? key})
      : super(
            key: key,
            height: 40,
            builder: (context, state) {
              Widget body;
              if (state == RefreshStatus.canRefresh) {
                body = const Text("释放更新");
              } else if (state == RefreshStatus.idle) {
                body = const Text("下拉刷新");
              } else if (state == RefreshStatus.refreshing) {
                body = Wrap(
                  spacing: 6,
                  children: const <Widget>[
                    CupertinoActivityIndicator(),
                    Text("刷新中..."),
                  ],
                );
              } else {
                body = Wrap();
              }
              return body;
            });
}

/// 自定义 FooterView
class RefreshFooter extends CustomFooter {
  RefreshFooter({Key? key})
      : super(
            key: key,
            height: 40,
            builder: (context, mode) {
              Widget body;
              if (mode == LoadStatus.idle) {
                body = const Text("上拉加载更多~");
              } else if (mode == LoadStatus.loading) {
                body = Wrap(
                  spacing: 6,
                  children: const <Widget>[
                    CupertinoActivityIndicator(),
                    Text("加载中..."),
                  ],
                );
              } else if (mode == LoadStatus.failed) {
                body = const Text("加载失败，点击重试~");
              } else {
                body = const Text("没有更多数据了~");
              }
              return SizedBox(
                height: 40,
                child: Center(child: body),
              );
            });
}
